﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.IO;
using System.Text;
using System;
using UnityEngine.UI;

namespace ABLocal
{
    public class SendToSMS : MonoBehaviour
    {
        public Button cli;
        // Start is called before the first frame update
        void Start()
        {
            url = url + strUid + "azh0724" + strKey + keys + strMob + "18501604724" + strContent + "你在本店的余额不足【汪汪披萨店】";
            cli.onClick.AddListener(() =>
            {
                Debug.Log(GetHtmlFromUrl(url));
            });
        }

        // Update is called once per frame
        void Update()
        {

        }
        string strUid = "Uid=";
        private string url = "http://utf8.sms.webchinese.cn/?";
        public string keys = "d41d8cd98f00b204e980";
        private string strMob = "&smsMob=";
        private string strContent = "&smsText=";
        string strKey = "&Key=";
        //调用时只需要把拼成的URL传给该函数即可。判断返回值即可
        public string GetHtmlFromUrl(string url)
        {
            string strRet = null;
            if (url == null || url.Trim().ToString() == "")
            {
                return strRet;
            }
            string targeturl = url.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                strRet = ser.ReadToEnd();
            }
            catch (Exception ex)
            {
                strRet = null;
            }
            return strRet;
        }
    }
}